<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>登录</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Cache-Control" content="no-transform">
		<meta name="format-detection" content="telephone=no">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" href="style/css/basic.css">
		<link rel="stylesheet" href="style/plugin/mui/css/mui.min.css" /> 
		<link rel="stylesheet" href="style/css/login.css" />
		<script type="text/javascript" src="style/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="style/plugin/mui/js/mui.min.js"></script>
		<script type="text/javascript" src="style/mockjs/dist/mock.js"></script>
		<script type="text/javascript" src="style/js/md5.js"></script>
		<script type="text/javascript" src="style/js/basic.js"></script>
		<style>
			/*#account{
				-webkit-appearance: none; 
			}*/
		</style>
	</head>

	<body>
		<div id="appLogin">
			<div class="login_bg"></div>
			<div class="login">
				<div class="mui-input-group" id='login-form'>
					<div class="mui-input-row">
						<label class="icon_phone"></label>
						<input id='account' type="number" class="mui-input-clear mui-input" placeholder="请输入手机号">
					</div>
					<div class="mui-input-row password">
						<label class="icon_psw"></label>
						<input id='password' type="password" class="mui-input-password mui-input-clear"  placeholder="请输入密码">
					</div>
					<div class="mui-content-padded">
						<button id='login' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
					</div> 
				</div>
			</div>
		</div>
		<script>
			 mui.plusReady(function(){
			 	var account=document.getElementById("account");
			 	var pwd=document.getElementById("password");
			 	var log=document.getElementById("login");
			 	var flag=true;
			 	mui.ajax(domain+"/basic/ticket",{//请求登陆接口
			    	dataType:"json",
			    	type:"post", 
			    	timeout:10000,
			    	headers:{'Content-Type':'application/json'},
			    	success:function(data){
			//  		alert(data.data)
			    		timed=""+myDate.getFullYear()+mon+day
			    		var si=$.md5($.md5(data.data+timed))
			//  		alert(si) 
			    		if(parseInt(timed)%2!=0){
			    			si=si.substring(0,16)
			    		}else{ 
			    			si=si.substring(16)    
			    		}
			//  		alert(si)
//			localStorage.removeItem("tick")
//			localStorage.removeItem("sig") 
			    		localStorage.setItem("tick",data.data)
			    		localStorage.setItem("sig",si)
			    	},
			    	error:function(xhr,type,errorThrown){
			    		console.log(type)
			
			    	}
			    })
			 	log.addEventListener("tap",function(e){
			 		e.preventDefault()
			 		var ticket=localStorage.getItem("tick") 
                    var sign=localStorage.getItem("sig")
			 		if(flag){
			 			var nwait=plus.nativeUI.showWaiting()
			 			flag=false;
					    setTimeout(function(){
							flag=true;
							nwait.close();
							//if(pflag!=2)mui.toast("服务器不稳定，请重试！",{duration:"short"})
							//openurl("sales_index")
						},2500)
					    if(account.value==""){
					    	nwait.close()
					    	mui.toast("请输入账号！")
					    }else if(pwd.value==""){
					    	nwait.close()
					    	mui.toast("请输入密码！")
					    }else{
					    	mui.ajax(domain+"/user/login?t="+ticket+"&"+"sign="+sign,{//请求登陆接口 
						    	data:{
						    		phone:account.value, 
						    		password:pwd.value 
						    	},  
						    	dataType:"json",
						    	type:"post", 
						    	timeout:10000,
						    	headers:{'Content-Type':'application/json'},
						    	success:function(data){console.log(data)
//						    		alert(ticket) 
//						    		alert(sign) 
						    		if(data.code==1){
						    			nwait.close()	
						    			mui.toast("登录成功",{duration:"short"})
						    			if(data.data==1){
						    				openurl("agent_index")//跳转页面
						    			}
						    			if(data.data==4){
						    				openurl("recommend_index")
						    			}
						    			if(data.data==2){
						    				openurl("sales_in_bound")
						    			} 
						    		}else if(data.code==0){	
						    			mui.toast("用户名或密码错误",{duration:"short"})
						    			nwait.close()  
						    		}
						    	},
						    	error:function(xhr,type,errorThrown){
						    		console.log(type)
						    		nwait.close()
						    		mui.toast("服务器不稳定，稍后再试！",{duration:"short"})
						    	}
						    })
					    }
			 		}
			 	})
			 	
			 })
		</script>
	</body>
</html>